#!/bin/bash
root_dir="/usr/local/edata"
log_dir="$root_dir/kafka/logs"
mode=$(cat mode)
echo "$(date +"%Y-%m-%d %H:%M:%S") INFO starting kafka in $mode mode"
node_id=$(cat node_id)
cluster_id=$(cat cluster_id)
if [ ! -f "$log_dir/meta.properties" ];then
    echo "node.id=$node_id" >> $root_dir/kafka/config/kraft/server.properties
    echo "broker.id=$node_id" >> $root_dir/kafka/config/kraft/server.properties
    echo "Formatting storage directory..."
    kafka-storage.sh format -t $cluster_id -c $root_dir/kafka/config/kraft/server.properties  
fi
kafka-server-start.sh -daemon $root_dir/kafka/config/kraft/server.properties
if [[ $? -eq 0 ]];then
    echo "$(date +"%Y-%m-%d %H:%M:%S") INFO kafka start success"
else
    echo "$(date +"%Y-%m-%d %H:%M:%S") ERROR kafka start error"
fi